package com.yyk.yiliao.ui.trade;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.util.Md5Util2;
import com.yyk.yiliao.util.rx.ApiService;
import com.yyk.yiliao.util.rx.RxUtils;
import com.yyk.yiliao.bean.UserbankUinfodetailedInfo;

import java.util.Map;
import java.util.TreeMap;

import butterknife.BindView;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 明细  详情
 */
public class Mingxi2Activity extends BaseActivity {
    @BindView(R.id.tv_typename) //充值名字
            TextView tvTypename;
    @BindView(R.id.tv_money)  //金额
            TextView tvMoney;
    @BindView(R.id.tv_type) //充值银行卡号
            TextView tvType;
    @BindView(R.id.tv_money_balance)//账号余额
            TextView tvMoneyBalance;
    @BindView(R.id.tv_time) //时间
            TextView tvTime;
    @BindView(R.id.tv_free)
    TextView tvFree;
    @BindView(R.id.tv_state)
    TextView tvState;
    @BindView(R.id.ll_free) //手续费
            LinearLayout llFree;
    @BindView(R.id.ll_state)//提现中
            LinearLayout llState;
    @BindView(R.id.ll_type) //充值银行卡号
            LinearLayout llType;
    @BindView(R.id.tv_type2) //支付方式
            TextView tvType2;
    @BindView(R.id.ll_type2)
    LinearLayout llType2;
    private String order_code;
    private String type;

    @Override
    public int getLayoutId() {
        return R.layout.activity_mingxi2;
    }

    @Override
    public void initView() {
        initToolbar();
    }

    private void initToolbar() {
        setBackArrow();
        setTitle(type);
    }

    @Override
    public void initData() {
        if (getBundle() != null) {
            order_code = getBundle().getString("order_code");
            type = getBundle().getString("type");
            Logger.e(order_code + "__" + type);

        }

        initPost();
    }

    private void initPost() {
        Map<String, String> map = new TreeMap<>();
        map.put("order_code", order_code + "");
        map.put("sign", Md5Util2.createSign(map));
        RxUtils.getInstance().retrofit.create(ApiService.class).postUserbankUinfodetailed(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<UserbankUinfodetailedInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
//                        Logger.e("明细列表" + "异常");

                    }

                    @Override
                    public void onNext(UserbankUinfodetailedInfo info) {
                        Logger.e("明细详情" + info.toString());
                        if (info.getCode() == 1) {
                            UserbankUinfodetailedInfo.DataBean data = info.getData();
                            if (type.equals("充值")) {
                                tvMoney.setText("+" + data.getMoney());
                                tvTime.setText(data.getTime());
                                tvMoneyBalance.setText(data.getMoney_balance() + "元");
                                tvType.setText(data.getType());
                                tvTypename.setText(type);

                                llState.setVisibility(View.GONE);
                                llFree.setVisibility(View.GONE);
                                llType2.setVisibility(View.GONE);
                            } else if (type.equals("提现")) {
                                tvMoney.setText("-" + data.getMoney());
                                tvTime.setText(data.getTime());
                                tvMoneyBalance.setText(data.getMoney_balance() + "元");
                                tvType.setText(data.getType());
                                tvFree.setText(data.getFee() + "元");
                                tvState.setText(data.getState());
                                tvTypename.setText(type);

                                llType2.setVisibility(View.GONE);
                            } else {
                llState.setVisibility(View.GONE);
                                llType.setVisibility(View.GONE);
                                llFree.setVisibility(View.GONE);
                                tvType2.setText(data.getType());
                                //消费
                                tvMoney.setText("-" + data.getMoney());
                                tvTime.setText(data.getTime());
                                tvMoneyBalance.setText(data.getMoney_balance() + "元");
                                tvType.setText(data.getType());
                                tvTypename.setText(type);
                            }
                        }

                    }
                });
    }


}
